package com.spring.springbootblog.common.utils;

import com.spring.springbootblog.common.pojo.dataobject.BlogInfo;
import com.spring.springbootblog.common.pojo.dataobject.UserInfo;
import com.spring.springbootblog.common.pojo.request.AddBlogParam;
import com.spring.springbootblog.common.pojo.request.UpBlogParam;
import com.spring.springbootblog.common.pojo.response.BlogDetailResponse;
import com.spring.springbootblog.common.pojo.response.BlogInfoResponse;
import com.spring.springbootblog.common.pojo.response.UserInfoResponse;
import org.springframework.beans.BeanUtils;

/**
 * 转换
 */
public class BeanConver {
    public static BlogDetailResponse transDetail(BlogInfo blogInfo) {
        BlogDetailResponse blogDetailResponse = new BlogDetailResponse();
        if(blogInfo != null) {
            BeanUtils.copyProperties(blogInfo, blogDetailResponse);
        }
        return blogDetailResponse;
    }
    public static BlogInfoResponse trans(BlogInfo blogInfo) {
        BlogInfoResponse blogInfoResponse = new BlogInfoResponse();
        if(blogInfo != null) {
            BeanUtils.copyProperties(blogInfo, blogInfoResponse);
        }
        return blogInfoResponse;
    }

    public static UserInfoResponse trans(UserInfo userInfo) {
        UserInfoResponse userInfoResponse = new UserInfoResponse();
        if(userInfo != null) {
            BeanUtils.copyProperties(userInfo, userInfoResponse);
        }
        return userInfoResponse;
    }

    public static BlogInfo trans(AddBlogParam param){
        BlogInfo blogInfo = new BlogInfo();
        BeanUtils.copyProperties(param, blogInfo);
        return blogInfo;
    }
    public static BlogInfo trans(UpBlogParam param){
        BlogInfo blogInfo = new BlogInfo();
        BeanUtils.copyProperties(param, blogInfo);
        return blogInfo;
    }
}
